package Factories;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import Draw.IDraw;


public class DrawBehaviourFactory {
	public IDraw buildDrawBehaviour(String param) {
	    Class<?> classe;
	    IDraw iDraw = null;
		
	    try { // Instanciation dynamique
			classe = Class.forName("Draw." + param);
		    Constructor<?> ct= classe.getConstructors()[0]; // On recupere son constructeur
		    iDraw =  (IDraw)ct.newInstance();
		} catch (ClassNotFoundException e) {
			System.out.println("ERROR: Class to build draw behaviour not found.");
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			System.out.println("ERROR: Unable to instantiate class " + param);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} 
		return iDraw;
	}
}
